package com.qidian.buy.search.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @Author 戴着假发的程序员
 * @Company 起点编程
 * @date 2023/5/23 13:44
 */
@Configuration
public class RestTemplateConfig {
    @Bean
    @LoadBalanced// 负载均衡
    public RestTemplate restTemplate(ClientHttpRequestFactory factory){
        return new RestTemplate(factory);
    }
    @Bean
    public SimpleClientHttpRequestFactory clientHttpRequestFactory(){
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        // 远程读取数据的超时时间
        factory.setReadTimeout(5000);//ms
        // 远程连接超时时间
        factory.setConnectTimeout(15000);//ms
        return factory;
    }
}
